package jnpf.engine.custom.cmd.tasks;

import jnpf.engine.util.SpringContextHolder;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.flowable.task.service.impl.persistence.entity.TaskEntityManager;

/**
 * @desc 取消委派的cmd
 */
public class CancelDelegateTaskCmd implements Command<Void> {
    protected  String taskId;
    protected  String initialAssignee;//原来的审批人
    @Override
    public Void execute(CommandContext commandContext) {
        SpringProcessEngineConfiguration springProcessEngineConfiguration = SpringContextHolder.getBean(SpringProcessEngineConfiguration.class);
        TaskEntityManager taskEntityManager = springProcessEngineConfiguration.getTaskServiceConfiguration().getTaskEntityManager();
        TaskEntity taskEntity = taskEntityManager.findById(taskId);
        taskEntity.setOwner(null);
        taskEntity.setAssignee(initialAssignee);
        taskEntity.setDelegationState(null);
        return null;
    }

    public CancelDelegateTaskCmd(String taskId, String initialAssignee) {
        this.taskId = taskId;
        this.initialAssignee = initialAssignee;
    }
}
